import request from '../utils/request';
import { mapToParam } from '../utils';

export function getTestReport({ report_name, project_name, fix_version, reporter, status }) {
  return request(`api/getTestReport/?report_name=${report_name}&project_name=${project_name}&fix_version=${fix_version}&reporter=${reporter}&status=${status}`, {
    method: 'GET',
    headers: {
      Accept: 'application/json',
      'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8', // 接收x-www-form-urlencoded类型的参数
    },
  });
}
export function addTestReport(reportparam) {
  return request('api/addTestReport/', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-type': 'application/json; charset=UTF-8',
    },
    body: JSON.stringify(reportparam),
  });
}
export function updateTestReport(reportparam) {
  return request('api/updateTestReport/', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    },
    body: mapToParam(reportparam),
  });
}

export function sendTestReport(reportparam) {
  return request('api/sendTestReport/', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    },
    body: mapToParam(reportparam),
  });
}

export function deleteFile(param) {
  return request('api/deleteFile/', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    },
    body: mapToParam(param),
  });
}

export function getTestReportJira({ fix_version, project_name }) {
  return request(`api/getTestReportJira/?fix_version=${fix_version}&project_name=${project_name}`, {
    method: 'GET',
    headers: {
      Accept: 'application/json',
      'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8', // 接收x-www-form-urlencoded类型的参数
    },
  });
}
// 需要用到的project信息
export function GetProjectList() {
  return request('api/GetProjectList/', {
    method: 'GET',
    headers: {
      Accept: 'application/json',
      'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8', // 接收x-www-form-urlencoded类型的参数
    },
  });
}

export function DownloadFile({ file_path }) {
  console.log(file_path);
  return request(`api/downloadAtta/?file_path=${file_path}`, {
    method: 'GET',
    headers: {
      Accept: 'application/json',
      'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    },
    // body: mapToParam(param),
  });
}
